function ArrayCheckUtils() {
};

ArrayCheckUtils.addToArray = function(array, inputElm, checkFunc, errorArr) {
  array[array.length] = { inputElm: inputElm, checkFunc: checkFunc, errorArr: errorArr };
  if (array.length == 1) {
    ArrayCheckUtils.next(array);
  }
};

ArrayCheckUtils.next = function(array) {
  if (array.length == 0) {
    return;
  }
  var func = function() { 
    array.splice(0, 1);
    ArrayCheckUtils.next(array);
  };
  var item = array[0];
  ArrayCheckUtils.removeErrors(item.inputElm, item.errorArr);
  item.checkFunc(item.inputElm, func, item.errorArr);
};

ArrayCheckUtils.removeErrors = function(inputElm, errorArr) {
  inputElm.style.color = '';
  inputElm.style.backgroundColor = '';
  for (var idx in errorArr) {
    var obj = errorArr[idx];
    if (obj.id == inputElm.id) {
      while (inputElm.parentNode.childNodes.length > 1) {
        inputElm.parentNode.removeChild(inputElm.parentNode.childNodes[1]);
      }
      errorArr.splice(idx, 1);
    }
  }
};

ArrayCheckUtils.addError = function(inputElm, errorArr, message) {
  var div = document.createElement('div');
  div.style.fontSize = '11px';
  div.style.color = '#ff0000';
  div.style.fontWeight = 'bold';
  div.style.padding = '0 0 3px 5px';
  inputElm.style.color = '#fff';
  inputElm.style.backgroundColor = '#ff0000';
  div.appendChild(document.createTextNode(message));
  inputElm.parentNode.appendChild(div);
  errorArr[errorArr.length] = inputElm;
}
